/**
     *
     */

package com.xyz.frame.api.controller;

import cn.hutool.json.JSONObject;
import com.google.common.collect.Lists;
import com.xyz.frame.common.response.ServerResponseEntity;
import com.xyz.frame.service.NormalService;
import io.swagger.v3.oas.annotations.Operation;
import io.swagger.v3.oas.annotations.tags.Tag;
import lombok.extern.slf4j.Slf4j;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.web.bind.annotation.GetMapping;
import org.springframework.web.bind.annotation.RequestParam;
import org.springframework.web.bind.annotation.RestController;

import java.util.List;
import java.util.Objects;

/**
 * 
 */
@RestController
@Tag(name = "题目接口")
@Slf4j
public class QuestionController {

    @Autowired
    private NormalService normalService;

    /**
     * question
     */
    @GetMapping("/question")
    @Operation(summary = "question", description = "question")
    public ServerResponseEntity<List<JSONObject>> question(@RequestParam("param") String param) {
        String condition = "";
        if(Objects.equals("76",param)){
            //背题模式
            condition = " and type = 99 ";
        }else {
            condition = " and type != 99 ";
        }
        List<cn.hutool.json.JSONObject> jsonObjects = normalService.listQuestion(condition);
        log.info("===>question=>jsonObjects:{}",jsonObjects);
        List<JSONObject> list = Lists.newArrayList();
        jsonObjects.stream().forEach(item -> {
            JSONObject jsonObject = new JSONObject();
            jsonObject.put("id",item.get("id"));
            //0判断题 1单选题 2多项选择题 3填空题 99背题模式
            jsonObject.put("type",item.get("type"));
            jsonObject.put("title",item.get("title"));
            if(Objects.equals("0",String.valueOf(item.get("type")))){
                JSONObject answer = new JSONObject();
                answer.put("rs",item.get("rs"));
                answer.put("ans",item.get("ans"));
                jsonObject.put("answer",answer);
            } else if(Objects.equals("1",String.valueOf(item.get("type")))){
                JSONObject answer = new JSONObject();
                answer.put("rs",item.get("rs"));
                String ans = item.get("ans").toString();
                String[] split = ans.split(";");
                answer.put("ans",split);
                jsonObject.put("answer",answer);
            } else if(Objects.equals("2",String.valueOf(item.get("type")))){

            } else if(Objects.equals("3",String.valueOf(item.get("type")))){

            } else if(Objects.equals("99",String.valueOf(item.get("type")))){

            }else {
                return;
            }
            list.add(jsonObject);
        });

//        List<JSONObject> list = Lists.newArrayList();
//        JSONObject jsonObject = new JSONObject();
//        jsonObject.put("id","1233");
//        JSONObject answer = new JSONObject();
//        answer.put("rs","0");
//        answer.put("ans","0");
//        jsonObject.put("answer",answer);
//        //0判断题 1单选题 2多项选择题 34填空题
//        jsonObject.put("type","0");
//        jsonObject.put("title","1.习近平强调，要“树立大农业观、大食物观，向耕地草原森林海洋向植物动物微生物要热量、要蛋白，全方位多途径开发食物资源”“既向陆地要食物，也向海洋要食物，耕海牧渔，建设海上牧场、“蓝色粮仓’”，构建多元化食物供给体系。“大农业观”“大食物观”突出体现的思维方式是");
//        list.add(jsonObject);
//
//        JSONObject jsonObject2 = new JSONObject();
//        jsonObject2.put("id","1234");
//        JSONObject answer2 = new JSONObject();
//        answer2.put("rs","0");
//        answer2.put("ans","0");
//        jsonObject2.put("answer",answer2);
//        //0判断题 1单选题 2多项选择题 34填空题
//        jsonObject2.put("type","0");
//        jsonObject2.put("title","1.习近平强调，要“树立大农业观、大食物观，向耕地草原森林海洋向植物动物微生物要热量、要蛋白，全方位多途径开发食物资源”“既向陆地要食物，也向海洋要食物，耕海牧渔，建设海上牧场、“蓝色粮仓’”，构建多元化食物供给体系。“大农业观”“大食物观”突出体现的思维方式是");
//        list.add(jsonObject2);

        return ServerResponseEntity.success(list);
    }
}
